package find_code;


//二分查找
public class BinarySearch {
    public static void main(String[] args) {
        int[] arr = {1,3,5,6,23,43,54,76,80};
        int number = 54;
        System.out.println(binarySearch(arr, number));
    }

    public static int binarySearch(int[] arr,int number){
        int min = 0;
        int max = arr.length - 1;
        while (min <= max){
            int mid = (max - min) / 2 + min;
            if(arr[mid] > number){
                max = mid - 1;
            } else if (arr[mid] < number) {
                min = mid + 1;
            }else {
                return mid;
            }
        }
        return -1;
    }
}
